package com.xiaobias.stuy;

import javax.swing.*;
import java.awt.event.ActionListener;
import java.util.Date;

/**
 * @author lw
 * @since 2023/6/20-22:30
 */
public class LambdaTimer {
    public static void main(String[] args) {
        // 使用 Runnable 这种方式的线程非常好
        Runnable runnable = () -> System.out.println(Thread.currentThread().getName() + " hello world");
        for (int i = 0; i < 5; i ++) {
            new Thread(runnable).start();
        }

        // 编写定时器代码，这个怎样写呢？
        ActionListener al = e -> System.out.println(new Date());
        Timer timer = new Timer(1000, al);
        timer.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        timer.stop();
    }
}
